

/*
The following codes replicate Tables 6 and 7

*/





*************************Table 6*******************************************************************
*************************Table 6*******************************************************************
*************************Table 6*******************************************************************

*----------------------------------------------------------------------------------------------------
* Part I: results for nonexporters:
* Columns 1, 3, 5, 7, 9, 11
*----------------------------------------------------------------------------------------------------

cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

keep if d_export==0
 
* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)


gen lnabsG_gdp=ln(absG_gdp)

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
drop if VMPL<0

*6.1. column 1:
reghdfe lnabsG_gdp  did   Llnl Ltfp_op  Llnage  LlnkL  LlnRD Lfinance2   ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear newid) cluster (ind4year)   
*-------------------------------------------------------------------------------
*6.2. column 3:
reghdfe lnabsG_gdp  did   Llnl Ltfp_op  Llnage  LlnkL  LlnRD Lfinance2  ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear newid) cluster (ind4year)   
*-------------------------------------------------------------------------------
*6.3. column 5:
reghdfe lnabsG_gdp  did   Llnl Ltfp_op  Llnage  LlnkL  LlnRD Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   
*-------------------------------------------------------------------------------

*6.4. column 7:
reghdfe lnabsG_gdp  did   Llnl Ltfp_op  Llnage  LlnkL  LlnRD Lfinance2  ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provowneryear newid) cluster (ind4year)   
*-------------------------------------------------------------------------------

*6.5. column 9:
reghdfe lnabsG_gdp  did   Llnl Ltfp_op  Llnage  LlnkL  LlnRD Lfinance2  ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(ind2year provowneryear newid) cluster (ind4year)   

*-------------------------------------------------------------------------------

*6.6 column 11 (extend 1 year)

 use "labor-basic-tpu-reg-1.dta",clear
sort newid t
gen d=0 if d_export==0
gen e=d
bysort newid: gen f1=(t[_n]-t[_n-1])
bysort newid:replace e=0 if d[_n]==. & d[_n-1]==0 & f1==0    /*往后延1年*/
keep if e==0

gen lnabsG_gdp=ln(absG_gdp)
                                                                  

xtset newid t
egen provyear=group(province  t)
egen ind2year=group(ind2_adj  t)
egen ind4year=group(ind4_adj  t)
egen owneryear=group(QiuType  t)
egen provindyear=group(province ind2_adj t)
egen provowneryear=group(province QiuType  t)


reghdfe lnabsG_gdp  did   Llnl Ltfp_op  Llnage  LlnkL  LlnRD Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)

*--------------------------------------------------------------------------------------------------------------




*----------------------------------------------------------------------------------------------------
* Part II: results for exporters:
* Columns 2, 4, 6, 8, 10, 12
*----------------------------------------------------------------------------------------------------


cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

keep if d_export==1
bysort newid: egen exp_max=max(export_intensity)
drop if exp_max==1      
* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)


gen lnabsG_gdp=ln(absG_gdp)

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
drop if VMPL<0

*6.1. column 2:
reghdfe lnabsG_gdp  did  Llnl  Ltfp_op   Llnage  LlnkL  LlnRD   export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear newid) cluster (ind4year)   

*6.2. column 4:
reghdfe lnabsG_gdp  did  Llnl  Ltfp_op   Llnage  LlnkL  LlnRD   export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear newid) cluster (ind4year)   

*6.3. column 6:
reghdfe lnabsG_gdp  did  Llnl  Ltfp_op   Llnage  LlnkL  LlnRD   export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   


*6.4. column 8:
reghdfe lnabsG_gdp  did  Llnl  Ltfp_op   Llnage  LlnkL  LlnRD   export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provowneryear newid) cluster (ind4year)   


*6.5. column 10:
reghdfe lnabsG_gdp  did  Llnl  Ltfp_op   Llnage  LlnkL  LlnRD   export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(ind2year provowneryear newid) cluster (ind4year)   
*---------------------------------------

*6.6 column 12 (extend 1 year)

cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

sort newid t
gen d=1 if d_export==1
gen e=d
bysort newid: gen f1=(t[_n]-t[_n-1])
bysort newid:replace e=1 if d[_n]==. & d[_n-1]==1 & f1==1    /*往后延1年*/
keep if e==1

gen lnabsG_gdp=ln(absG_gdp)
                                                                  

xtset newid t
egen provyear=group(province  t)
egen ind2year=group(ind2_adj  t)
egen ind4year=group(ind4_adj  t)
egen owneryear=group(QiuType  t)
egen provindyear=group(province ind2_adj t)
egen provowneryear=group(province QiuType  t)


reghdfe lnabsG_gdp  did  Llnl  Ltfp_op   Llnage  LlnkL  LlnRD   export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   










*************************Table 7*******************************************************************
*************************Table 7*******************************************************************
*************************Table 7*******************************************************************

*----------------------------------------------------------------------------------------------------
* Part I: results for nonexporters:
* Columns 1, 3, 5, 7, 9, 11
*----------------------------------------------------------------------------------------------------


cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

keep if d_export==0 
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007


gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)


 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)
 egen indyear=group(ind2 t)



*7.1 column 1:
reghdfe lnabs_k  did  Llnl   Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear newid) cluster (ind4year)   

*7.2. column 3:
reghdfe lnabs_k  did  Llnl   Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear newid) cluster (ind4year)   

*7.3. column 5:
reghdfe lnabs_k  did  Llnl   Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   


*7.4. column 7:
reghdfe lnabs_k  did  Llnl   Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provowneryear newid) cluster (ind4year)   


*7.5. column 9:
reghdfe lnabs_k  did  Llnl   Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2    ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind export_intensity,  ///
absorb(indyear provowneryear newid) cluster (ind4year)  
*----------------------------------------------------------------------------------------


use "labor-basic-tpu-reg-1.dta",clear
sort newid t
gen d=0 if d_export==0
gen e=d
bysort newid: gen f1=(t[_n]-t[_n-1])
bysort newid:replace e=0 if d[_n]==. & d[_n-1]==0 & f1==0    /*往后延1年*/
keep if e==0

bysort newid: egen exp_max=max(export_intensity)
drop if exp_max==1    
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0

/*
* distribution of VMPK
twoway (kdensity VMPK if VMPK<5.3, color(red)),  xtitle(VMPK) ytitle(Distribution)
graph export "D:\Nanjing\2020\wage gap\RR\results\VMPK_dist.eps",replace
*/


*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007

/*
gen gdp_def=1
replace gdp_def=1.063 if t==1999
replace gdp_def=1.177 if t==2000
replace gdp_def=1.302 if t==2001
replace gdp_def=1.428 if t==2002
replace gdp_def=1.819 if t==2003
replace gdp_def=1.899 if t==2004
replace gdp_def=2.198 if t==2005
replace gdp_def=2.575 if t==2006
replace gdp_def=3.170 if t==2007
*/

gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)

                                                                  

xtset newid t
egen provyear=group(province  t)
egen ind2year=group(ind2_adj  t)
egen ind4year=group(ind4_adj  t)
egen owneryear=group(QiuType  t)
egen provindyear=group(province ind2_adj t)
egen provowneryear=group(province QiuType  t)

* 7.6 : column 11
reghdfe lnabs_k  did  Llnl   Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   



*=======================================================================================




*----------------------------------------------------------------------------------------------------
* Part II: results for exporters:
* Columns 1, 3, 5, 7, 9, 11
*----------------------------------------------------------------------------------------------------

cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

 keep if d_export==1
bysort newid: egen exp_max=max(export_intensity)
drop if exp_max==1    
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0

/*
* distribution of VMPK
twoway (kdensity VMPK if VMPK<5.3, color(red)),  xtitle(VMPK) ytitle(Distribution)
graph export "D:\Nanjing\2020\wage gap\RR\results\VMPK_dist.eps",replace
*/


*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007

/*
gen gdp_def=1
replace gdp_def=1.063 if t==1999
replace gdp_def=1.177 if t==2000
replace gdp_def=1.302 if t==2001
replace gdp_def=1.428 if t==2002
replace gdp_def=1.819 if t==2003
replace gdp_def=1.899 if t==2004
replace gdp_def=2.198 if t==2005
replace gdp_def=2.575 if t==2006
replace gdp_def=3.170 if t==2007
*/

gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)


 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)
 egen indyear=group(ind2 t)
 

*-----------------------------------------------------------------------------------------

*7.7. column 2:
reghdfe lnabs_k  did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provyear newid) cluster (ind4year)   

*------------------------------------------------------------------------------------------
*7.8. column 4:
reghdfe lnabs_k  did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear newid) cluster (ind4year)   
*------------------------------------------------------------------------------------------
*7.9. column 6:
reghdfe lnabs_k  did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   

*------------------------------------------------------------------------------------------
*7.10. column 8:
reghdfe lnabs_k  did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(provowneryear newid) cluster (ind4year)   

*------------------------------------------------------------------------------------------
*7.11. column 10:
reghdfe lnabs_k  did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 hhi5_lns_ind Llnk_ind ,  ///
absorb(indyear owneryear newid) cluster (ind4year)  

*------------------------------------------------------------------------------------------


use "labor-basic-tpu-reg-1.dta",clear
sort newid t
gen d=1 if d_export==1
gen e=d
bysort newid: gen f1=(t[_n]-t[_n-1])
bysort newid:replace e=1 if d[_n]==. & d[_n-1]==1 & f1==1    /*往后延1年*/
keep if e==1

bysort newid: egen exp_max=max(export_intensity)
drop if exp_max==1    
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0

/*
* distribution of VMPK
twoway (kdensity VMPK if VMPK<5.3, color(red)),  xtitle(VMPK) ytitle(Distribution)
graph export "D:\Nanjing\2020\wage gap\RR\results\VMPK_dist.eps",replace
*/


*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007

/*
gen gdp_def=1
replace gdp_def=1.063 if t==1999
replace gdp_def=1.177 if t==2000
replace gdp_def=1.302 if t==2001
replace gdp_def=1.428 if t==2002
replace gdp_def=1.819 if t==2003
replace gdp_def=1.899 if t==2004
replace gdp_def=2.198 if t==2005
replace gdp_def=2.575 if t==2006
replace gdp_def=3.170 if t==2007
*/

gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)

                                                                  

xtset newid t
egen provyear=group(province  t)
egen ind2year=group(ind2_adj  t)
egen ind4year=group(ind4_adj  t)
egen owneryear=group(QiuType  t)
egen provindyear=group(province ind2_adj t)
egen provowneryear=group(province QiuType  t)

* 7.12: column 12
reghdfe lnabs_k did Llnl  Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(owneryear provyear newid) cluster (ind4year)   


